<template>
  <!-- 头部部分 -->
  <header class="header">
    <h1>todos</h1>
    <input
      class="new-todo"
      placeholder="请输入任务名称"
      autofocus
      @keyup.enter="add"
      v-model.trim="todoName"
    />
  </header>
</template>

<script>
export default {
  data() {
    return {
      todoName: "",
    };
  },
  methods: {
    add() {
      if (this.todoName === "") {
        return alert("不可以为空");
      }
      const todo = { id: Date.now(), name: this.todoName, isDone: false };
      this.$emit("todoName", todo);
      this.todoName = "";
    },
  },
};
</script>

<style lang="scss" scoped>
</style>